
const u = {
    async getLocation({ type = "gcj02" }) {
        let result = [undefined, undefined]
        try {
            let getLocation = await uni.getLocation({ type })
            getLocation.longitude = Number(getLocation.longitude.toFixed(6))
            getLocation.latitude = Number(getLocation.latitude.toFixed(6))
            result[1] = getLocation
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async showLoading({ title = "", mask = true }) {
        return uni.showLoading({ title, mask })
    },
    async hideLoading() {
        return uni.hideLoading()
    },
    async toast({ title = "", duration = 2500, mask = false }) {
        if (typeof title != "string") {
            title = JSON.stringify(title)
        }
        uni.showToast({ title, icon: "none", duration, mask })
        return await new Promise(resolve => setTimeout(resolve, duration))
    },
    async confirm({ title = "", content = "", confirmColor = "" }) {
        if (typeof title != "string") title = JSON.stringify(title)
        return new Promise((resolve) => {
            uni.showModal({
                title,
                content,
                confirmColor,
                success({ confirm }) {
                    resolve(confirm)
                }
            })
        })
    },
    async login() {
        let result = [undefined, undefined]
        try {
            let { code } = await uni.login()
            result[1] = code
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async getUserProfile(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.getUserProfile(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async checkSession() {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.checkSession()
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async navigateTo(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.navigateTo(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async scanCode(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.scanCode(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async getScreenBrightness(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.getScreenBrightness(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async canvasToTempFilePath(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.canvasToTempFilePath(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async setClipboardData(...arg) {
        let result = [undefined, undefined]
        try {
            result[1] = await uni.setClipboardData(...arg)
        } catch (err) {
            result[0] = err
        }
        return result
    },
    async uploadFile(...arg) {
        let result = [undefined, undefined]
        try {
            let { data } = await uni.uploadFile(...arg)
            result[1] = JSON.parse(data).data
        } catch (err) {
            result[0] = err
        }
        return result
    },
    env: uni.env,
    hideTabBar: () => uni.hideTabBar(),
    request: (...arg) => uni.request(...arg),
    createOffscreenCanvas: (...arg) => uni.createOffscreenCanvas(...arg),
    createSelectorQuery: (...arg) => uni.createSelectorQuery(...arg),
    createMapContext: (...arg) => uni.createMapContext(...arg),
    createInnerAudioContext: (...arg) => uni.createInnerAudioContext(...arg),
    getImageInfo: (...arg) => uni.getImageInfo(...arg),
    getFileSystemManager: (...arg) => uni.getFileSystemManager(...arg),
    getSystemInfoSync: () => uni.getSystemInfoSync(),
    navigateBack: () => uni.navigateBack(),
    reLaunch: (...arg) => uni.reLaunch(...arg),
    setScreenBrightness: (...arg) => uni.setScreenBrightness(...arg),
    vibrateShort: (...arg) => uni.vibrateShort(...arg),
    getStorageSync: (...arg) => uni.getStorageSync(...arg),
    setStorageSync: (...arg) => uni.setStorageSync(...arg),
    removeStorageSync: (...arg) => uni.removeStorageSync(...arg),
    previewImage: (...arg) => uni.previewImage(...arg),
    pageScrollTo: (...arg) => uni.pageScrollTo(...arg),
    setNavigationBarTitle: (...arg) => uni.setNavigationBarTitle(...arg),
}

export default u